﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;
using DevExpress.XtraTreeList.Nodes;
using DevExpress.XtraEditors;


namespace ERP.Classes
{
    public class cs_hmr_donviInfo
    {
        private string _madonvi;
        private string _tendonvi;
        private string _chucnang;
        private string _diachi;
        private string _msthue;
        private string _sodt_fax;
        private string _captren;
        private string _ngaythanhlap;
        private string _qdthanhlap;
        private string _noidungthanhlap;
        private string _ngayhuy;
        private string _soqdhuy;
        private string _noidunghuy;
        private int _trangthai;
        private string _ngaynhap;
        private int _nguoinhap;
        private string _ngaysua;
        private int _nguoisua;
        private int _capdonvi;
        private int _loaidv;

        public cs_hmr_donviInfo()
        {
            this._madonvi = " ";
            this._tendonvi = " ";
            this._chucnang = " ";
            this._diachi = " ";
            this._msthue = " ";
            this._sodt_fax = " ";
            this._captren = " ";
            this._ngaythanhlap = " ";
            this._qdthanhlap = " ";
            this._noidungthanhlap = " ";
            this._ngayhuy = " ";
            this._soqdhuy = " ";
            this._noidunghuy = " ";
            this._trangthai = 0;
            this._ngaynhap = " ";
            this._nguoinhap = 0;
            this._ngaysua = " ";
            this._nguoisua = 0;
            this._capdonvi = 0;
            this._loaidv = 0;

        }
        public string madonvi
        {
            get
            {
                return this._madonvi;
            }
            set
            {
                this._madonvi = value;
            }
        }
        public string tendonvi
        {
            get
            {
                return this._tendonvi;
            }
            set
            {
                this._tendonvi = value;
            }
        }
        public string chucnang
        {
            get
            {
                return this._chucnang;
            }
            set
            {
                this._chucnang = value;
            }
        }
        public string diachi
        {
            get
            {
                return this._diachi;
            }
            set
            {
                this._diachi = value;
            }
        }
        public string msthue
        {
            get
            {
                return this._msthue;
            }
            set
            {
                this._msthue = value;
            }
        }
        public string sodt_fax
        {
            get
            {
                return this._sodt_fax;
            }
            set
            {
                this._sodt_fax = value;
            }
        }
        public string captren
        {
            get
            {
                return this._captren;
            }
            set
            {
                this._captren = value;
            }
        }
        public string ngaythanhlap
        {
            get
            {
                return this._ngaythanhlap;
            }
            set
            {
                this._ngaythanhlap = value;
            }
        }
        public string qdthanhlap
        {
            get
            {
                return this._qdthanhlap;
            }
            set
            {
                this._qdthanhlap = value;
            }
        }
        public string noidungthanhlap
        {
            get
            {
                return this._noidungthanhlap;
            }
            set
            {
                this._noidungthanhlap = value;
            }
        }
        public string ngayhuy
        {
            get
            {
                return this._ngayhuy;
            }
            set
            {
                this._ngayhuy = value;
            }
        }
        public string soqdhuy
        {
            get
            {
                return this._soqdhuy;
            }
            set
            {
                this._soqdhuy = value;
            }
        }
        public string noidunghuy
        {
            get
            {
                return this._noidunghuy;
            }
            set
            {
                this._noidunghuy = value;
            }
        }
        public int trangthai
        {
            get
            {
                return this._trangthai;
            }
            set
            {
                this._trangthai = value;
            }
        }
        public string ngaynhap
        {
            get
            {
                return this._ngaynhap;
            }
            set
            {
                this._ngaynhap = value;
            }
        }
        public int nguoinhap
        {
            get
            {
                return this._nguoinhap;
            }
            set
            {
                this._nguoinhap = value;
            }
        }
        public string ngaysua
        {
            get
            {
                return this._ngaysua;
            }
            set
            {
                this._ngaysua = value;
            }
        }
        public int nguoisua
        {
            get
            {
                return this._nguoisua;
            }
            set
            {
                this._nguoisua = value;
            }
        }
        public int capdonvi
        {
            get
            {
                return this._capdonvi;
            }
            set
            {
                this._capdonvi = value;
            }
        }
        public int loaidv
        {
            get
            {
                return this._loaidv;
            }
            set
            {
                this._loaidv = value;
            }
        }

        public int ExcuteStoreProcedure(string storeProcedure, int option)
        {
            string[] paraName = new string[21];
            paraName[0] = "@madonvi";
            paraName[1] = "@tendonvi";
            paraName[2] = "@chucnang";
            paraName[3] = "@diachi";
            paraName[4] = "@msthue";
            paraName[5] = "@sodt_fax";
            paraName[6] = "@captren";
            paraName[7] = "@ngaythanhlap";
            paraName[8] = "@qdthanhlap";
            paraName[9] = "@noidungthanhlap";
            paraName[10] = "@ngayhuy";
            paraName[11] = "@soqdhuy";
            paraName[12] = "@noidunghuy";
            paraName[13] = "@trangthai";
            paraName[14] = "@ngaynhap";
            paraName[15] = "@nguoinhap";
            paraName[16] = "@ngaysua";
            paraName[17] = "@nguoisua";
            paraName[18] = "@capdonvi";
            paraName[19] = "@loaidv";
            paraName[20] = "@option";
            object[] paraValue = new object[21];
            paraValue[0] = this._madonvi;
            paraValue[1] = this._tendonvi;
            paraValue[2] = this._chucnang;
            paraValue[3] = this._diachi;
            paraValue[4] = this._msthue;
            paraValue[5] = this._sodt_fax;
            paraValue[6] = this._captren;
            paraValue[7] = this._ngaythanhlap;
            paraValue[8] = this._qdthanhlap;
            paraValue[9] = this._noidungthanhlap;
            paraValue[10] = this._ngayhuy;
            paraValue[11] = this._soqdhuy;
            paraValue[12] = this._noidunghuy;
            paraValue[13] = this._trangthai;
            paraValue[14] = this._ngaynhap;
            paraValue[15] = this._nguoinhap;
            paraValue[16] = this._ngaysua;
            paraValue[17] = this._nguoisua;
            paraValue[18] = this._capdonvi;
            paraValue[19] = this._loaidv;
            paraValue[20] = option;
            csCSDL csdl = new csCSDL();
            int i = 0;
            i = csdl.CreateParameters(paraName, 21, paraValue);
            return csdl.ExcuteStoreProcedure(storeProcedure);
        }
        public void KetDulieuVaoListview(ListView myList)
        {
            csListView list = new csListView();
            string[] fields = new string[20];
            fields[0] = "madonvi";
            fields[1] = "tendonvi";
            fields[2] = "chucnang";
            fields[3] = "diachi";
            fields[4] = "msthue";
            fields[5] = "sodt_fax";
            fields[6] = "captren";
            fields[7] = "ngaythanhlap";
            fields[8] = "qdthanhlap";
            fields[9] = "noidungthanhlap";
            fields[10] = "ngayhuy";
            fields[11] = "soqdhuy";
            fields[12] = "noidunghuy";
            fields[13] = "trangthai";
            fields[14] = "ngaynhap";
            fields[15] = "nguoinhap";
            fields[16] = "ngaysua";
            fields[17] = "nguoisua";
            fields[18] = "capdonvi";
            fields[19] = "loaidv";
            list.KetDulieu(myList, "HMR_DONVI", "", fields);
        }
        public int ExcuteProcedure(int option)
        {
            return this.ExcuteStoreProcedure("Proc_HMR_DONVI", option);
        }

        //public void ShowDataInCombo(ComboBox cbo, string condition)
        //{
        //    csComboBox cb = new csComboBox("tendonvi", "madonvi");
        //    cb.KetDuLieu(cbo, "HMR_DONVI", condition);
        //}

        public int ShowDataGrid(DataGrid datagrid, string condition)
        {
            csDataGrid grid = new csDataGrid();

            string[] header = new string[20];
            header[0] = "madonvi";
            header[1] = "tendonvi";
            header[2] = "chucnang";
            header[3] = "diachi";
            header[4] = "msthue";
            header[5] = "sodt_fax";
            header[6] = "captren";
            header[7] = "ngaythanhlap";
            header[8] = "qdthanhlap";
            header[9] = "noidungthanhlap";
            header[10] = "ngayhuy";
            header[11] = "soqdhuy";
            header[12] = "noidunghuy";
            header[13] = "trangthai";
            header[14] = "ngaynhap";
            header[15] = "nguoinhap";
            header[16] = "ngaysua";
            header[17] = "nguoisua";
            header[18] = "capdonvi";
            header[19] = "loaidv";

            string[] mappingname = new string[20];
            mappingname[0] = "madonvi";
            mappingname[1] = "tendonvi";
            mappingname[2] = "chucnang";
            mappingname[3] = "diachi";
            mappingname[4] = "msthue";
            mappingname[5] = "sodt_fax";
            mappingname[6] = "captren";
            mappingname[7] = "ngaythanhlap";
            mappingname[8] = "qdthanhlap";
            mappingname[9] = "noidungthanhlap";
            mappingname[10] = "ngayhuy";
            mappingname[11] = "soqdhuy";
            mappingname[12] = "noidunghuy";
            mappingname[13] = "trangthai";
            mappingname[14] = "ngaynhap";
            mappingname[15] = "nguoinhap";
            mappingname[16] = "ngaysua";
            mappingname[17] = "nguoisua";
            mappingname[18] = "capdonvi";
            mappingname[19] = "loaidv";

            int[] colwidth = new int[20];
            colwidth[0] = 30;
            colwidth[1] = 360;
            colwidth[2] = 1200;
            colwidth[3] = 2400;
            colwidth[4] = 150;
            colwidth[5] = 150;
            colwidth[6] = 30;
            colwidth[7] = 90;
            colwidth[8] = 600;
            colwidth[9] = 2400;
            colwidth[10] = 90;
            colwidth[11] = 600;
            colwidth[12] = 2400;
            colwidth[13] = 12;
            colwidth[14] = 90;
            colwidth[15] = 12;
            colwidth[16] = 90;
            colwidth[17] = 12;
            colwidth[18] = 12;
            colwidth[19] = 12;
            csCSDL csdl = new csCSDL();
            return grid.CreateTableStyle("HMR_DONVI", datagrid, csdl.OpenTable("HMR_DONVI", condition), header, mappingname, colwidth, 20);
        }
        public int Get_Info()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                ds = csdl.OpenTable("HMR_DONVI", "madonvi = '" + this._madonvi + "'");
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    return 0;
                }
                this._madonvi = ds.Tables[0].Rows[0]["madonvi"].ToString().Trim();
                this._tendonvi = ds.Tables[0].Rows[0]["tendonvi"].ToString().Trim();
                this._chucnang = ds.Tables[0].Rows[0]["chucnang"].ToString().Trim();
                this._diachi = ds.Tables[0].Rows[0]["diachi"].ToString().Trim();
                this._msthue = ds.Tables[0].Rows[0]["msthue"].ToString().Trim();
                this._sodt_fax = ds.Tables[0].Rows[0]["sodt_fax"].ToString().Trim();
                this._captren = ds.Tables[0].Rows[0]["captren"].ToString().Trim();
                this._ngaythanhlap = ds.Tables[0].Rows[0]["ngaythanhlap"].ToString().Trim();
                this._qdthanhlap = ds.Tables[0].Rows[0]["qdthanhlap"].ToString().Trim();
                this._noidungthanhlap = ds.Tables[0].Rows[0]["noidungthanhlap"].ToString().Trim();
                this._ngayhuy = ds.Tables[0].Rows[0]["ngayhuy"].ToString().Trim();
                this._soqdhuy = ds.Tables[0].Rows[0]["soqdhuy"].ToString().Trim();
                this._noidunghuy = ds.Tables[0].Rows[0]["noidunghuy"].ToString().Trim();
                this._trangthai = Convert.ToInt32(ds.Tables[0].Rows[0]["trangthai"].ToString().Trim());
                this._ngaynhap = ds.Tables[0].Rows[0]["ngaynhap"].ToString().Trim();
                this._nguoinhap = Convert.ToInt32(ds.Tables[0].Rows[0]["nguoinhap"].ToString().Trim());
                this._ngaysua = ds.Tables[0].Rows[0]["ngaysua"].ToString().Trim();
                this._nguoisua = Convert.ToInt32(ds.Tables[0].Rows[0]["nguoisua"].ToString().Trim());
                this._capdonvi = Convert.ToInt32(ds.Tables[0].Rows[0]["capdonvi"].ToString().Trim());
                this._loaidv = Convert.ToInt32(ds.Tables[0].Rows[0]["loaidv"].ToString().Trim());
                return 1;
            }
            catch
            {
                return -1;
            }
        }

        public int Get_Info_by_Parents()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                ds = csdl.OpenTable("HMR_DONVI", "captren = '" + this._captren + "'");
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    return 0;
                }
                this._madonvi = ds.Tables[0].Rows[0]["madonvi"].ToString().Trim();
                this._tendonvi = ds.Tables[0].Rows[0]["tendonvi"].ToString().Trim();
                this._chucnang = ds.Tables[0].Rows[0]["chucnang"].ToString().Trim();
                this._diachi = ds.Tables[0].Rows[0]["diachi"].ToString().Trim();
                this._msthue = ds.Tables[0].Rows[0]["msthue"].ToString().Trim();
                this._sodt_fax = ds.Tables[0].Rows[0]["sodt_fax"].ToString().Trim();
                this._captren = ds.Tables[0].Rows[0]["captren"].ToString().Trim();
                this._ngaythanhlap = ds.Tables[0].Rows[0]["ngaythanhlap"].ToString().Trim();
                this._qdthanhlap = ds.Tables[0].Rows[0]["qdthanhlap"].ToString().Trim();
                this._noidungthanhlap = ds.Tables[0].Rows[0]["noidungthanhlap"].ToString().Trim();
                this._ngayhuy = ds.Tables[0].Rows[0]["ngayhuy"].ToString().Trim();
                this._soqdhuy = ds.Tables[0].Rows[0]["soqdhuy"].ToString().Trim();
                this._noidunghuy = ds.Tables[0].Rows[0]["noidunghuy"].ToString().Trim();
                this._trangthai = Convert.ToInt32(ds.Tables[0].Rows[0]["trangthai"].ToString().Trim());
                this._ngaynhap = ds.Tables[0].Rows[0]["ngaynhap"].ToString().Trim();
                this._nguoinhap = Convert.ToInt32(ds.Tables[0].Rows[0]["nguoinhap"].ToString().Trim());
                this._ngaysua = ds.Tables[0].Rows[0]["ngaysua"].ToString().Trim();
                this._nguoisua = Convert.ToInt32(ds.Tables[0].Rows[0]["nguoisua"].ToString().Trim());
                this._capdonvi = Convert.ToInt32(ds.Tables[0].Rows[0]["capdonvi"].ToString().Trim());
                this._loaidv = Convert.ToInt32(ds.Tables[0].Rows[0]["loaidv"].ToString().Trim());
                return 1;
            }
            catch
            {
                return -1;
            }
        }

        public DataSet Get_List()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                string sql = "select a.madonvi, a.tendonvi, a.captren"
                        + " from hmr_donvi a"
                        + " where a.trangthai = 1"
                        + " order by a.madonvi asc";
                ds = csdl.SelecSQL(sql);
                               
                return ds;
            }
            catch
            {
                return null;
            }
        }

        public DataSet Get_List_1()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                string sql = "select rtrim(a.madonvi) as madonvi, rtrim(a.tendonvi) as tendonvi"
                        + " from hmr_donvi a"
                        + " where a.trangthai = 1"
                        + " order by a.madonvi asc";
                ds = csdl.SelecSQL(sql);

                return ds;
            }
            catch
            {
                return null;
            }
        }

        public DataSet GetListNV(string madv)
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");

            try
            {
                string sql = "select a.manhanvien, a.nhanvien_id, a.hoten, b.hinhanh, a.ngaysinh, a.diachi, a.didong, a.socmnd, a.ngaycap, a.noicap, a.chuyenmon, a.sotruong, a.ngoaingu "
                        + " from hmr_nhanvien a"
                        + " left join HINHANH b on (b.manhanvien = a.manhanvien)"
                        + " where a.trangthai = 0 "
                        + " and a.manhanvien in (select manhanvien from hmr_nv_pb where maphongban = '" + madv + "' and trangthai = 0)"
                        + " order by a.manhanvien";
                ds = csdl.SelecSQL(sql);
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    return null;
                }
                return ds;
            }
            catch
            {
                return null;
            }

        }

        public DataSet GetListNVMoi(string madv)
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");

            try
            {
                string sql = "select a.nhanvien_id, a.hoten, b.hinhanh, a.ngaysinh, a.diachi, a.didong, a.socmnd, a.ngaycap, a.noicap, a.chuyenmon, a.sotruong, a.ngoaingu "
                        + " from hmr_nhanvien a"
                        + " left join HINHANH b on (b.manhanvien = a.manhanvien)"
                        + " where a.trangthai = 0 "
                        + " and a.manhanvien not in (select manhanvien from hmr_nv_pb)"
                        + " order by a.manhanvien";
                ds = csdl.SelecSQL(sql);
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    return null;
                }
                return ds;
            }
            catch
            {
                return null;
            }

        }

    }
}
